#define BOOST_TEST_MODULE testElementFieldType

#include <boost/test/unit_test.hpp>

#include "common/elements/element_maker.h"
#include "common/elements/field_type.h"

BOOST_AUTO_TEST_CASE(testFieldTypeJson)
{
    auto first = std::make_shared<Elements::FieldType>();
    first->setId(1);
    first->setItemTypeId(2);
    first->setCaption("a");
    first->setDescription("b");
    first->setValueType(Elements::FieldType::ValueType::Integer);
    first->setIsBoardVisible(true);

    const auto json = first->toJsonString();
    const Elements::ElementPtr second(Elements::fromJsonString(json));
    BOOST_CHECK(first->isSame(second.get()));

    const auto third = std::static_pointer_cast<Elements::FieldType>(second);
    BOOST_CHECK(1 == third->id());
    BOOST_CHECK(2 == third->itemTypeId());
    BOOST_CHECK("a" == third->caption());
    BOOST_CHECK("b" == third->description());
    BOOST_CHECK(Elements::FieldType::ValueType::Integer == third->valueType());
    BOOST_CHECK(true == third->isBoardVisible());
}
